<template>
  <div class="form-model search-model">
    <div v-for="item in formaltSearch" :class="{'item-box':true,flexGrow2:item.type=='time'}">
      <span :title="item.name">{{item.name}}</span>
      <el-input v-if="item.type=='input'" v-model="search[item.key]" :readonly="canEdit" :placeholder="item.placeholder" @blur="changeParams(item)"></el-input>
      <el-date-picker
        v-else-if="item.type=='time'"
        v-model="search[item.key]"
        :type="path=='/socailServe/exam'?'datetimerange':'daterange'"
        range-separator="至"
        @change="changeParams(item)"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        >
      </el-date-picker>
      <el-select v-else-if="item.type=='select'" @change="changeParams(item)" filterable clearable v-model="search[item.key]" placeholder="请选择" :readonly="canEdit">
        <el-option
          v-for="(option,optIndex) in item.array"
          :key="optIndex"
          :label="(option?option.label:option)||option"
          :value="(option?option.value:option)||option"
          
          >
        </el-option>
      </el-select>
    </div>
  </div>
</template>
<script>
export default {
  props:['searchData',"search","canEdit","pageInfo"],
  components: {},
  name: "",
  data() {
    return {
      path:"",
        searchData1:[],

      searchDataurl:[
        "/student",
        "/teacherManage/info"
      ]
    };
  },
  computed: {
    formaltSearch(){
      var path = _g.getRouterPath(this)
      var goals=false
      for(var i=0;i<this.searchDataurl.length;i++){
        if(path.indexOf(this.searchDataurl[i])>-1){
          goals=true
          break;
        }
      }
      return goals?this.searchData:this.searchData1
    }
  },
  methods: {
    changeParams(item){
      if(item.type=="time"){
        if(this.path=='/socailServe/exam'){
          this.$store.state.search.params[item.key]=[_g.formatTime(this.search[item.key][0],"time"),_g.formatTime(this.search[item.key][1],"time")]
        }else{
          this.$store.state.search.params[item.key]=[_g.formatTime(this.search[item.key][0]),_g.formatTime(this.search[item.key][1])]
          this.search[item.key]=[_g.formatTime(this.search[item.key][0]),_g.formatTime(this.search[item.key][1])]
        }
      }else if(item.key.split("_")[0]=="sepcialSelect"){
        var params=JSON.parse(JSON.stringify(this.search))
        var array=[
          ["cet4","cet6","computers"],//技能证书
          ["scholarship_state","scholarship_remarkable","scholarship_inspirational","scholarship_school","scholarship_society",],//荣获奖学金
          ["difficulty_study","difficulty_family","difficulty_economics","difficulty_netword",],//困难类型
          ["subsidies_first","subsidies_second","subsidies_third","subsidies_society"],//助学金
          ["excellent_pacesetter","excellent_school_student","excellent_school_cadre","excellent_faculty_student","excellent_faculty_cadre","excellent_graduate"],//荣获称号
        ]
        var goal=array[item.key.split("_")[1]]
        goal.forEach(ele=>{
          this.search[ele]=""
        })
        if(this.search[item.key])this.search[this.search[item.key]]=1
      } else{
        if(item.check && this.search[item.key] && !item.checkMethods.test(this.search[item.key])){
          _g.toastMsg("warning","时间格式不正确")
          this.search[item.key]=""
          return
        }
        if(item.key=="position_time"){
          this.$store.state.search.params[item.key]=[this.search[item.key].split(",")[0],this.search[item.key].split(",")[1]]
        }
        this.$store.state.search.params[item.key]=this.search[item.key]
      }
      if(this.pageInfo)this.pageInfo.page=1
    },
      getsearchData(){
          var path = _g.getRouterPath(this)
          var tablename = ''
          this.$store.state.commonMenu.forEach(ele => {
              if (ele.children) {
                  tablename = ele.children.find(val => val.url == path) ? ele.children.find(val => val.url == path).tablename : tablename ? tablename : ""
              } else if (ele.url === path) {
                  tablename = ele.tablename
              }
          });
          if(tablename){
              _g.apiPost("teacher/getselect", {name:tablename}).then(res => {
                  this.searchData1 = res.data;
              })
          }

      }
  },
  created() {
    this.path=this.$router.history.current.fullPath
      this.getsearchData();
  }
};
</script>
<style scoped>
.form-model{
  display: flex;
  flex-wrap: wrap;
  border-left: 1px solid #E4E4E4;
}
.form-model .item-box{
  width:calc(100%/4);
  height: 45px;
  box-sizing: border-box;
  flex-flow: 1;
  display: flex;
}
.form-model .flexGrow2{
  /* width: 50%; */
  flex-flow: 2!important
}
.form-model .item-box span{
  float: left;
  width: 30%;

  line-height: 44px;
  height: 45px;
  overflow: hidden;
  color: #666;
  font-size: 12px;
  box-sizing: border-box;
  /* padding-right: 3px; */
  text-align: center;
  background-color: #f9fafc;
  border-bottom: 1px solid #E4E4E4;
  border-right: 1px solid #E4E4E4;
}
.wd100>div{
  width: 100%!important;
}
.wd100>div>span{
  width: calc(8% - 5px)!important;
}
</style>